﻿//debugger;
jQuery.extend({
    rpSpecChars :{url : { " ":"%20", "%":"%25", "=":"%3D", "+":"%2B", "#":"%23", "&":"%26" },
                  str : { "\\":"\\\\", "\"":"\\\"", "\'":"\\\'" } },
    rpSpecRegs : {url : null, str : null},
    CMData : function(type, ag, c)
    {
        //debugger;
        if( !c ) c = '';
        if( !jQuery.rpSpecRegs[ type ] )
        {
            var t = '';
            for(var srg in jQuery.rpSpecChars[ type ])
            {
                t += srg;
            }
            t='[' + t.replace(/([\$\(\)\\\[\*\+\.\?\^\{\|])/g,'\\$1') +  "]";
            jQuery.rpSpecRegs[ type ] = new RegExp(t,"gi");
        }
        
        var re = '', sm='';
        var l = ag.length;
        //var c = '%A4';
        if( l == 0 ) { return {};};
        if( l>1 )
        {
            for( var i=1; i<l; i++)
            {
                
                sm += c + jQuery.rlc( ag[i], jQuery.rpSpecChars[ type ] );
            }
        }
        re += jQuery.rlc( ag[0], jQuery.rpSpecChars[ type ] ) + sm + '';
        //return {msg:re};
        return re;
    },
    C2Msg : function( )
    {
        return { 
                    msg : jQuery.CMData( "url", arguments, '%A4'), 
                    Format : function()
                    {
                        this.mfmt = jQuery.CMData( "url", arguments, '%A4');
                        return this;
                    },
                    ErrFmt : function()
                    {
                        this.efmt = jQuery.CMData( "url", arguments, '');
                        return this;
                    },
                    end : function()
                    {
                        if( this[ "Format" ] ) delete this["Format"];
                        if( this[ "ErrFmt" ] ) delete this["ErrFmt"];
                        delete this["end"];
                        return this;
                    }
               }
    }, 
    CStr2Data : function( )
    {
        return jQuery.CMData( "str", arguments) 
    }, 
    rlc : function( str,reg )
    { 
              
      return str.replace( reg,//---/[\\"'%=&\+ ]/gi
          function( a )
          {
              //debugger;
              return jQuery.rpChar[ a ];
          });
    }
});
